<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增问答</title>
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/common.css" media="all">
    <script src="/js/layui/layui.all.js"></script>
    <script src="/js/utils.js"></script>
</head>
<body>
<form class="layui-form" style="padding-right: 20px;">
    <div class="layui-form-item">
        <label class="layui-form-label">招生问题</label>
        <div class="layui-input-block">
            <input type="text" id="question" name="question" required lay-verify="required" placeholder="招生问题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">答案</label>
        <div class="layui-input-block">
            <textarea placeholder="答案" id="answen" name="answen" required lay-verify="required" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="tijiao">提交</button>
            <button class="layui-btn" lay-submit lay-filter="close">关闭</button>
        </div>
    </div>
</form>
</body>
<script>
    var $ = layui.$,form= layui.form,layer=layui.layer;
    var qaid = getQueryVariable('qaid');
    $.ajax({
        url:"/wenda/getDetail",
        data:{"qaid":qaid},
        success:function (res) {
            if(res.code==200){
                let obj = res.data;
                $("#question").val(obj.question);
                $("#answen").val(obj.answen);
            }
        }
    })
    form.on("submit(close)",function (data) {
        parent.layui.layer.closeAll();
        return false;
    })
    form.on("submit(tijiao)",function (data) {
        data.field.qaid= qaid;
        data.field.question =  replaceReg(data.field.question);  // 替换
        data.field.answen =  replaceReg(data.field.answen);  // 替换
        layer.confirm('确定提交数据?', {icon: 3, title:'提示'}, function(index){
            $.ajax({
                url:"/wenda/update",
                type:"post",
                contentType:"application/json",
                data:JSON.stringify(data.field),
                success:function (res) {
                    console.log(res);
                    if(res.code==200){
                        layer.msg("修改成功");
                        setTimeout(function () {
                            parent.layui.layer.closeAll();
                        },500)
                    }else{
                        layer.msg(res.msg);
                    }
                }
            })
            layer.close(index);
        });
        return false;
    })
</script>
</html>